﻿<!DOCTYPE html>
<html>
<head>
    <title>添加栏目</title>
</head>
<body>

    <div class="tabarea1">
        <div id="area" class="area" style="overflow-y:auto;">
            <div class="form" id="form1">
                <input type="hidden" field="Lft" />
                <div class="title" style="margin-top: 0">
                    <span class="icon icon1"></span>基本
                </div>
                <div class="fl">
                    <div class="label">上级栏目：</div>
                    <div class="in">
                        <span class="input">
                            <select field="ParentId" class="tb_normal ui-box">
                                <option value="1" style="color: Red" selected="selected">一根目录一</option>
                                ${categories}
                            </select>
                        </span>
                        <span class="desc" style="color: Red">注:上级栏目指定后,不可修改!</span>
                    </div>
                </div>

                <div class="fl">
                    <div class="label"><span class="red">*</span>名称： </div>
                    <div class="in">
                        <input type="text" class="tb_normal ui-box ui-validate" required="true" length="[0,50]" summary="{required:'不能为空!',length:'长度不能超过50位!'}" field="Name" id="name" />
                    </div>
                </div>
                <div class="fl">
                    <div class="label"><span class="red">*</span>栏目标识：</div>
                    <div class="in">
                        <input type="text" class="tb_normal ui-box ui-validate" field="Tag" id="tag" size="20" /><span class="ui-button w80 middle-button" summary="{required:'不能为空',strerr:'长度为50位以下的字母，数字，下划线和连接线的组合'}">
                            <span class="button-inner">
                                <span class="button-txt">自动标识</span>
                                <a href="javascript:;"></a>
                            </span>
                        </span>
                        <br /><span class="desc">建议手动填写,用于调用数据的唯一标识,且显示在地址栏中,如http://to2.net/cms/news/,news就是一个标识</span>
                    </div>
                </div>

                <div class="fl">
                    <div class="label">重定向：</div>
                    <div class="in">

                        <input type="radio" class="radio" field="IsRedirect" name="IsRedirect" id="IsRedirect1" value="0" checked="checked" /><label for="IsRedirect1">否</label>
                        <input type="radio" class="radio" field="IsRedirect" name="IsRedirect" id="IsRedirect2" value="1" /><label for="IsRedirect1">是</label>

                        <span id="redirectPanel" class="hidden" style="padding-left: 20px">
                            网址(URL)：<input class="tb_normal ui-box ui-validate" length="[0,150]" name="location" field="Location" />
                        </span>
                        <br /> <span class="desc">提示：重定向可以将栏目页面跳转到指定的网址。</span>
                    </div>
                </div>
                <div class="fl">
                    <div class="label"> 图标：</div>
                    <div class="in">
                        <img id="icon_img" style="display: none; width: 80px; height: 80px; position: absolute; left: 5px; top: 0px" />
                        <input class="tb_normal ui-box ui-validate" length="[0,100]" type="text" readonly="readonly" field="Icon" id="icon" />
                        <span class="ui-button w80 middle-button" id="upload_icon">
                            <span class=" button-inner">
                                <span class="button-txt">上传缩略图</span>
                                <a href="javascript:;"></a>
                            </span>
                        </span>
                    </div>
                </div>
                <div class="fl hidden">
                    <div class="label">模块：</div>
                    <div class="in">
                        <select class="tb_normal ui-box" field="ModuleId">${categoryTypes}</select>
                    </div>
                </div>
                <div class="fl hidden">
                    <div class="label">排序：</div>
                    <div class="in">

                        <input class="tb_normal ui-box ui-validate" isnumber="true" field="SortNumber" style="width: 50px;" value="0" />
                    </div>
                </div>

                <div class="title">
                    <span class="icon icon1"></span>模板设置
                </div>
                <div class="fl">
                    <div class="label">栏目视图：</div>
                    <div class="in">
                        <select field="CategoryTemplate" id="CategoryTemplate" class="tb_normal ui-box"><option value="">一默认一</option>${category_tpls} </select><span class="desc">注：默认则使用模块的视图设置</span>
                    </div>
                </div>


                <div class="fl">
                    <div class="label">文档视图：</div>
                    <div class="in">
                        <select field="CategoryArchiveTemplate" id="CategoryArchiveTemplate" class="tb_normal ui-box"> <option value="">一默认一</option>${archive_tpls}</select><span class="desc">注：默认则使用模块（或文档）的视图设置</span>
                    </div>
                </div>

                <div class="title">
                    <span class="icon icon1"></span>SEO设置
                </div>
                <div class="fl">
                    <div class="label">标题：</div>
                    <div class="in">
                        <textarea class="tb_normal ui-box ui-validate" length="[0,100]" field="PageTitle" name="PageTitle" style="width: 500px; height: 25px;"></textarea>
                    </div>
                </div>
                <div class="fl">
                    <div class="label">关键字：</div>
                    <div class="in">

                        <textarea class="tb_normal ui-box ui-validate" length="[0,100]" field="Keywords" style="width: 500px; height: 25px;"></textarea>
                    </div>
                </div>
                <div class="fl">
                    <div class="label">描述：</div>
                    <div class="in">
                        <textarea class="tb_normal ui-box ui-validate" length="[,200]" field="Description" style="width: 500px; height: 75px;"></textarea>
                    </div>
                </div>

                <div class="fl">
                    <div class="label">&nbsp;</div>
                    <div class="in">
                        <span class="ui-button w150" id="btn">
                            <span class="button-inner">
                                <span class="button-txt">添加</span>
                                <input type="button" />
                            </span>
                        </span>
                    </div>
                </div>

                <div style="height:60px" class="clear-fix"></div>
            </div>
        </div>

    </div>
    <script type="text/javascript">
        var tag = jr.$("tag"),
        nameEle = jr.$("name");
        jr.json.bind('form1',${entity});

        //上传图标
        var icon_upload = jr.upload({
            id: 'upload_icon',
            debug: !true,
            url: '?module=upload&action=uploadimage&for=&upload.id=icon_upload',
            exts: '*.gif;*.jpg;*.png;*.bmp'
        }, function (result, data) {
            if (result) {
                jr.$('icon').value = data.url;
                jr.$('icon_img').src = data.url;
            } else {
                alert('上传失败：' + data);
            }
        });

        var redirectPanel = jr.$('redirectPanel');
        jr.$('IsRedirect1').onchange = jr.$('IsRedirect2').onchange = function(){
            if(this.checked){
                if(this.value == '1'){
                    redirectPanel.className = '';
                }else {
                    redirectPanel.className = 'hidden';
                }
            }
        };

        tag.onblur = function () {
            if (this.value == '') {
                jr.validator.setTip(this.nextSibling, false, 'required');
            } else {
                this.value = this.value.toLowerCase();
                if (!/^[a-z0-9_-]{1,50}$/.test(this.value)) {
                    jr.validator.setTip(this.nextSibling, false, 'strerr');
                } else {
                    jr.validator.removeTip(this.nextSibling);
                }
            }
        };


        tag.nextSibling.onclick = function () {
            var e = this;
            var txt = this.innerHTML;
            var _title = nameEle.value;
            if (_title == '') {
                jr.validator.setTip(e, false, null, '请先输入栏目名称!');
            } else {
                this.innerHTML = '获取中...';
                jr.xhr.post('?', 'module=ajax&action=getspellword&word=' + encodeURIComponent(_title), function (result) {
                    e.previousSibling.value = result.toLowerCase();
                    e.previousSibling.onblur();
                    e.innerHTML = txt;
                }, function () {
                    jr.validator.setTip(e, false, null, '获取失败,请重试!');
                });
            }
        };

        window.saveData = function () {
            if (jr.validator.validate('form1')) {
                var data = jr.json.toObject('form1');
                if(data.IsRedirect=='0')data.Location='';
                jr.xhr.jsonPost(
                     '${url}',
                     data,
                     function (json) {
                         if (json.result) {
                             if (window._reloadTree) window._reloadTree(0);
                             jr.dialog.alert(json.message || '栏目创建成功',function (){
                                 jr.load2('pl', 'category', 'update', 'category_id=' + json.data);
                             });
                         } else {
                             jr.dialog.alert(json.message);
                         }
                     });
            }
        };

        jr.$('btn').onclick = window.saveData;
        jr.validator.init('form1');
    </script>


</body>
</html>
